package com.ljf.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ljf.annotation.HasPermission;
import com.ljf.dto.StoreInPageQuery;
import com.ljf.entity.DetailStoreGoods;
import com.ljf.service.DetailStoreGoodsService;
import com.ljf.service.GoodsStoreService;
import com.ljf.service.SupplierService;
import com.ljf.util.Result;
import com.ljf.vo.DetailStoreGoodsVo;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.validation.constraints.NotEmpty;
import java.util.List;
import java.util.Map;

@RestController
@Validated
@RequestMapping("/inventory_management/detail_store_goods_in")
public class StoreInController {

    @Autowired
    private DetailStoreGoodsService detailStoreGoodsService;
    @Autowired
    private SupplierService supplierService;

    @HasPermission("inventory_management:detail_store_goods_in:save")
    @GetMapping("/queryOptionsSuppliers")
    public Result queryOptionsSuppliers() {
        List<Map<String, Object>> list = supplierService.queryOptionsSuppliers();
        return Result.success(list);
    }

    /**
     * 分页查询
     * @param si
     * @return
     */
    @HasPermission("inventory_management:detail_store_goods_in:list")
    @PostMapping("/queryPageByQo")
    public Result queryPageByQo(StoreInPageQuery si) {
        Page<DetailStoreGoodsVo> page = detailStoreGoodsService.queryPage(si);
        return Result.success(page);
    }

    /**
     * 添加
     * @param detailStoreGoods
     * @param request
     * @return
     */
    @HasPermission("inventory_management:detail_store_goods_in:save")
    @PostMapping("/save")
    public Result saveIn(DetailStoreGoods detailStoreGoods, HttpServletRequest request) {
        detailStoreGoodsService.saveIn(detailStoreGoods, (String) request.getHeader("token"));
        return Result.success();
    }

    /**
     * 删除
     * @param cn
     * @return
     */
    @HasPermission("inventory_management:detail_store_goods_in:delIn")
    @PostMapping("/delIn")
    public Result delIn(@NotEmpty(message = "系统编号不能为空") String cn) {
        detailStoreGoodsService.deleteIn(cn);
        return Result.success();
    }
}
